package com.acwing.partition3;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2022/2/11 18:57
 */
public class AC239奇偶游戏_带权并查集 {

    private static final int N = 20010;
    private static Map<Integer, Integer> map = new HashMap<>(N);
    private static int[] parent = new int[N], dist = new int[N];

    private static int n = 0, m = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        m = Integer.parseInt(reader.readLine());
        n = 0;
        int ans = m;
        for (int i = 0; i < N; i++) parent[i] = i;
        for (int i = 1; i <= m; i++) {
            String[] ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]) - 1, b = Integer.parseInt(ss[1]);
            a = get(a);
            b = get(b);
            int t = 0;
            if ("odd".equals(ss[2])) t = 1;
            int pa = find(a), pb = find(b);
            if (pa == pb) {
                if ((dist[a] + dist[b]) % 2 != t) {
                    ans = i - 1;
                    break;
                }
            } else {
                dist[pa] = (dist[a] + dist[b] + t) % 2;
                parent[pa] = pb;
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int get(int x) {
        if (!map.containsKey(x)) map.put(x, ++n);
        return map.get(x);
    }

    private static int find(int x) {
        if (x != parent[x]) {
            int root = find(parent[x]);
            dist[x] = (dist[x] + dist[parent[x]]) % 2;
            parent[x] = root;
        }
        return parent[x];
    }
}
